package com.lenovo.mso2o.ui.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lenovo.framework.base.BaseDialogFragment;
import com.lenovo.mso2o.R;
import com.lenovo.mso2o.ui.SignInCameraActivity;

/**
 * Created by lenovo on 2016/3/17.
 */
public class SignFailureChoiceFragment extends BaseDialogFragment {
    private String ticketid = "";
    private String error_info = "";
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ticketid = getArguments().getString(SignFailureChoiceFragment.this.getActivity().getString(R.string.ticketid));
        error_info = getArguments().getString(SignFailureChoiceFragment.this.getActivity().getString(R.string.location_invalid_info));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View view = inflater.inflate(R.layout.sign_failure_list, container);
        TextView errorInfoView = (TextView) view.findViewById(R.id.no_gps_or_not_in_range);
        errorInfoView.setText(error_info);
        TextView btPhoto = (TextView) view.findViewById(R.id.bt_sign_failure_upload_photo);
        btPhoto.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SignFailureChoiceFragment.this.getActivity(), SignInCameraActivity.class);
                intent.putExtra(SignFailureChoiceFragment.this.getActivity().getString(R.string.ticketid), ticketid);
                startActivity(intent);
                dismiss();
            }
        });
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
//                        int downY = (int) event.getY() + outHeight * 2;
                        int downY = (int) event.getY();
                        if (isOutDistrict(downY, v)) {
                            dismiss();
                        }
                        break;
                }
                return false;
            }
        });
        return view;
    }
}
